package com.zzyl.nursing.controller.member;
/*
 *预约信息Controller
 *@Autor Adam
 *@Date  2025/7/31  20:26
 *
 */

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;

import com.zzyl.nursing.service.ReservationService;
import com.zzyl.nursing.vo.CountTimeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;


@RestController
@RequestMapping("/member/reservation")
public class ReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;

    /**
     * 查询当天取消的预约的数量
     *
     * @return
     */
    @GetMapping("/cancelled-count")
    public AjaxResult CancelledCount() {
        Long userId = UserThreadLocal.getUserId();
        Long count = reservationService.CancelledCount(userId);
        return success(count);
    }

    /**
     * 查询每个时间段剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public AjaxResult CountByTime(Long time) {
        List<CountTimeVo> countTimeVoList = reservationService.CountByTime(time);
        return success(countTimeVoList);
    }

    /**
     * 新增预约
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody Reservation reservation){
        reservationService.add(reservation);
        return success();
    }

    /**
     * 分页查询预约信息
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo<List<Reservation>> page(){
        startPage();
        List<Reservation> reservationList = reservationService.list();
        return getDataTable(reservationList);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public AjaxResult updateById(Long id){
        reservationService.updateById(id);
        return success();
    }



}
